package ch20;
/**
 * Write a method to shuffle a deck of cards. It must be a perfect shuffle - 
 * in other words, each 52! permutations of the deck has to be equally likely. 
 * Assume that you are given a random number generator which is perfect.
 * @author Ray
 *
 */
public class ch20_2 {

	public static void shuffle(int[] cards){
		int temp,index;
		for(int i=0;i<cards.length;i++){
			index = i+(int)(Math.random()*(cards.length-i));
			temp = cards[i];
			cards[i] = cards[index];
			cards[index] = temp;
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] card = {1,2,3,4,5};
		shuffle(card);
		for(int i=0;i<card.length;i++)
			System.out.print(card[i]+" ");
	}

}
